package hot100;

import java.util.LinkedList;

public class Solution739 {
    public int[] dailyTemperatures(int[] temperatures) {
        int len = temperatures.length;
        int[] res = new int[len];
        LinkedList<int[]> stack = new LinkedList<>();
        for (int i = 0; i < len; i++) {
            while (!stack.isEmpty() && stack.getLast()[0] < temperatures[i]) {
                int[] cur = stack.removeLast();
                res[cur[1]] = i - cur[1];
            }
            stack.add(new int[]{temperatures[i], i});
        }
        return res;
    }
}
